package com.only4play.productcenter.infrastructre.converter;

import com.only4play.productcenter.api.constans.DirectionType;
import com.only4play.productcenter.api.constans.InOutStoreType;
import com.only4play.productcenter.domain.product.ProductType;

import java.util.Objects;

/**
 * @author zlm
 * @date 2024/1/15
 */
public class CustomMapper {

  public ProductType int2ProductType(Integer code) {
    if (Objects.isNull(code)) {
      return null;
    }
    return ProductType.of(code).orElse(null);
  }

  public Integer productType2Int(ProductType productType) {
    return productType.getCode();
  }

  public DirectionType int2DirectionType(Integer code) {
    if (Objects.isNull(code)) {
      return null;
    }
    return DirectionType.of(code).orElse(null);
  }

  public Integer directionType2Int(DirectionType directionType) {
    return directionType.getCode();
  }

  public InOutStoreType int2InOutStoreType(Integer code) {
    if (Objects.isNull(code)) {
      return null;
    }
    return InOutStoreType.of(code).orElse(null);
  }

  public Integer inOutStoreType2Int(InOutStoreType inOutStoreType) {
    return inOutStoreType.getCode();
  }
}
